package cn.yaboya.system.controller;



import cn.yaboya.basic.utils.AjaxResult;
import cn.yaboya.system.domain.Dictionarydetail;
import cn.yaboya.system.service.IDictionarydetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "数字字典的API",description="部门相关的CRUD功能")
@RestController
@RequestMapping("/dicType")
public class DictionarydetailController {

    @Autowired
    private IDictionarydetailService dictionarydetailService;

    @DeleteMapping("{id}")
    @ApiOperation(value = "id删除" )
    public AjaxResult remove(@PathVariable("id") Long id){
        System.out.println(id);
        try {
            dictionarydetailService.remove(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，稍后再试");
        }
    }
    /**
     * @Title: addOrUpt
     * @Description: 增加 或者修改接口
     * @Author: LT
     * @Version: 1.0
     * @Date:  2022/6/24 12:41
     * @Parameters: [employee]
     * @Return cn.yaboya.basic.utils.AjaxResult
     */
    @ApiOperation(value = "新增或者修改" )
    @PutMapping
    public AjaxResult addOrUpt(@ApiParam(name="json 对象",required = true) @RequestBody Dictionarydetail dictionarydetail){
        try {
            // 判断是否有id 没有就新增 有就更改
            if (dictionarydetail.getId() == null){
                dictionarydetailService.add(dictionarydetail);
            } else {
                dictionarydetailService.update(dictionarydetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，稍后再试");
        }
    }



    /**
     * @Title: batchRem
     * @Description: 批量删除
     * @Author: LT
     * @Version: 1.0
     * @Date:  2022/6/25 11:28
     * @Parameters: [ids]
     * @Return cn.yaboya.basic.utils.AjaxResult
     */
    @PatchMapping
    public AjaxResult batchRem(@RequestBody Long[] ids){
        try {
            dictionarydetailService.batchRem(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，稍后再试");
        }
    }

}
